class Solution {
public:
    vector<int> findThePrefixCommonArray(vector<int>& A, vector<int>& B)
    {
        int n = A.size();
        vector<int> ans(n);
        unordered_map<int, int> hashA;
        unordered_map<int, int> hashB;
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            hashA[A[i]]++;
            hashB[B[i]]++;
            if (A[i] == B[i])
                sum++;
            else
                sum += hashA[B[i]] + hashB[A[i]];
            ans[i] = sum;
        }
        return ans;
    }
};